#ifndef VIEWERTHREAD_H
#define VIEWERTHREAD_H

#include <QObject>
#include <QThread>
#include <QDebug>

class ViewerThread : public QObject
{
    Q_OBJECT
public:
    explicit ViewerThread(QObject *parent = nullptr);
    static void stop(void)
    {
        _stop=1;
    }
    static void start(void)
    {
        _stop=0;
    }
    static void IP(const QString _hostName, quint16 _port)
    {
        hostName = _hostName;
        port = _port;
    }

signals:
    void resultReady(const QString &result);

public slots:
    void doWork(const QString &parameter) ;

private:
    //SocketClient *socket_client;
    static uint8_t _stop;
    static QString hostName;
    static quint16 port;

//    void client(void);
//    void download(void);
//    void local(void);
};

class ControllerViewerThread : public QObject
{
    Q_OBJECT
    QThread workerThread;
public:
    ControllerViewerThread() {
        //Worker *worker = new Worker;
        worker = new ViewerThread();
        worker->moveToThread(&workerThread);
        connect(&workerThread, &QThread::finished, worker, &QObject::deleteLater);
        connect(this, &ControllerViewerThread::operate, worker, &ViewerThread::doWork);
        connect(worker, &ViewerThread::resultReady, this, &ControllerViewerThread::handleResults);
        workerThread.start();
    }
    ~ControllerViewerThread() {
        workerThread.quit();
        workerThread.wait();
    }

    void start(void)
    {
        emit operate("start");
    }

    ViewerThread *worker;
public slots:
    void handleResults(const QString &)
    {
        ;
    }
signals:
    void operate(const QString &);
};

#endif // VIEWERTHREAD_H
